﻿using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;

namespace littleAdminHelper
{
    class dumpInfoToCsv : Dumper
    {

        ArrayList keys;
        ArrayList values;


        public dumpInfoToCsv(){
            this.filename="debug.csv";
            this.keys=new ArrayList();
            this.values=new ArrayList();
        }

        public override void dump()
        {
            TextWriter tw = new StreamWriter(this.path + "\\" + this.filename);
            tw.Write(this.toString());
            tw.Close();
        }
        
        public void generateText()
        {
            this.flushText();
            foreach (String key in this.keys){
                this.text+=key+";";
            }
            this.text+="\r\n";

            foreach(String value in this.values){
                this.text+=value+";";
            }
        }

        public override void addText(string input)
        {

            if (!input.Equals("") || input != null) {
                input = input.Replace("\r\n", ";");
                input = input.Replace("\n", ";");

                String[] values = input.Split(';');

                for (int i = 0; i < values.Length; i++)
                {
                    if (values[i] != "")
                    {

                        String[] data = values[i].Split(':');
                        this.keys.Add(data[0].Trim());
                        this.values.Add(data[1].Trim());
                       

                        if (data.Length > 2)
                        {
                            for (int j = 2; j < data.Length; j++)
                            {
                                this.values[this.values.Count-1]+= ":" + data[j];
                            }
                        }



                    }
                    
                }
            }
        }

        public override string toString()
        {
            this.generateText();
            return this.text;
        }

    }
}
